import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { Response } from './common/response'
import { HttpFilter } from './common/filter'
import { ValidationPipe } from '@nestjs/common'
import { join } from 'path';
import * as session from 'express-session'
 
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.use(session({
    secret: 'abcd',
    resave: false, // 将 resave 选项设置为 false
    saveUninitialized: false, // 将 saveUninitialized 选项设置为 false
    name: 'abcd.session',
    rolling: true,
    cookie: { maxAge: null },
  }))
  app.enableCors()//处理跨域
  // app.useGlobalInterceptors(new Response())
  app.useGlobalFilters(new HttpFilter())
  app.useGlobalPipes(new ValidationPipe())

  app.useStaticAssets(join(__dirname, 'images'),
    {
      prefix: '/xiaoluo/images' 
    }
  )

  const options = new DocumentBuilder().setTitle('博客管理系统').setDescription('接口接口文档').setVersion('1').build()
  const document = SwaggerModule.createDocument(app, options)
  SwaggerModule.setup('/api-docs', app, document)
  await app.listen(3000);
}
bootstrap();
